<!DOCTYPE html>
<html>

<!-- Mirrored from www.zi-han.net/theme/hplus/table_data_tables.html by HTTrack Website Copier/3.x [XR&CO'2014], Wed, 20 Jan 2016 14:20:01 GMT -->
<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">


    <title>试题管理</title>
    <meta name="keywords" content="H+后台主题,后台bootstrap框架,会员中心主题,后台HTML,响应式后台">
    <meta name="description" content="H+是一个完全响应式，基于Bootstrap3最新版本开发的扁平化主题，她采用了主流的左右两栏式布局，使用了Html5+CSS3等现代技术">

    <link rel="shortcut icon" href="../../favicon.ico">
    <link href="${ctx}/css/bootstrap.min14ed.css?v=3.3.6" rel="stylesheet">
    <link href="${ctx}/css/font-awesome.min93e3.css?v=4.4.0" rel="stylesheet">

    <!-- Data Tables -->
    <link href="${ctx}/css/plugins/dataTables/dataTables.bootstrap.css" rel="stylesheet">
    <link href="${ctx}/css/plugins/iCheck/custom.css" rel="stylesheet">
<#--<link href="${ctx}/css/animate.min.css" rel="stylesheet">-->
    <link href="${ctx}/css/style.min862f.css?v=4.1.0" rel="stylesheet">
    <script src="${ctx}/js/jquery.min.js?v=2.1.4"></script>
    <script src="${ctx}/js/plugins/layer/layer.js"></script>
    <script src="${ctx}/js/bootstrap.min.js?v=3.3.6"></script>
    <script src="${ctx}/js/plugins/jeditable/jquery.jeditable.js"></script>
    <script src="${ctx}/js/plugins/dataTables/jquery.dataTables.min.js"></script>
    <script src="${ctx}/js/plugins/dataTables/dataTables.bootstrap.js"></script>
    <script src="${ctx}/js/content.min.js?v=1.0.0"></script>
    <script src="${ctx}/js/plugins/iCheck/icheck.min.js"></script>
    <script src="${ctx}/js/template.js"></script>


    <style type="text/css">
        .stem {
            text-align: left;
            box-sizing: border-box;
            overflow: hidden;
            white-space: nowrap;
            text-overflow: ellipsis;
            width: 280px;
            text-decoration: underline;
        }

        /*表头居中*/
        thead tr th {
            text-align: center;
        }

        tbody tr td {
            text-align: center;
        }

        div.dataTables_info {
            padding-top: 6px;
        }
    </style>
</head>

<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">

                <div class="ibox-content">
                    <div class="text-center">
                        <form class="form-inline">
                        <#--审核状态-->
                            <div class="form-group">
                                <label class="control-label">审核状态</label>
                                <select class="form-control" id="check-status-id">
                                    <option value="-1">全部</option>
                                    <option value="0">未审核</option>
                                    <option value="1">一审未过</option>
                                    <option value="2">一审通过</option>
                                    <option value="3">二审未过</option>
                                    <option value="4">二审通过</option>
                                </select>
                            </div>
                        <#--认知层次-->
                            <div class="form-group">
                                <label class="control-label">认知层次</label>
                                <select class="form-control" id="cognitive-level">
                                    <option value="-1">全部</option>
                                    <#list cognitiveLevelList as listKey>
                                        <option value="${listKey.name}">${listKey.name}</option>
                                    </#list>
                                </select>
                            </div>
                        <#--试题分类-->
                            <div class="form-group">
                                <label class="control-label">科目分类</label>
                                <select class="form-control" id="examClass" onchange="getCategory()">
                                    <option value="-1">全部</option>
                                <#list examClass as ec>
                                    <option value="${ec.id}">${ec.name}</option>
                                </#list>
                                </select>
                            </div>
                            <div class="form-group">
                                <label class="control-label">试题分类</label>
                                <select class="form-control" id="category">
                                    <option value="-1">全部</option>
                                </select>
                            </div>
                            <div class="form-group">
                                <div class="col-sm-3">
                                    <input type="text" class="form-control" name="keywords" placeholder="请输入关键字"/>
                                </div>
                            </div>
                            <div class="form-group">
                                <a class="btn btn-primary" id="search-exam">筛选试题</a>
                                <a class="btn btn-success" href="#" onclick="exportExam()">批量导出</a>
                            </div>
                            <a href="javascript:location.reload();" class="pull-right btn btn-default"><i
                                    class="glyphicon glyphicon-refresh"></i></a>
                        </form>
                    </div>
                    <table class="table table-striped table-bordered table-hover dataTables-example" id="examTable">
                        <thead>
                        <tr>
                            <th width="8px"><label class='i-checks'><input type="checkbox" id="all_checked"></label></th>
                            <th>题干</th>
                            <th width="125px">分类</th>
                            <th width="30px">总分</th>
                            <th>大纲代码</th>
                            <th width="60px">认知层次</th>
                            <th width="130px">更新时间</th>
                            <th>审核状态</th>
                            <th width="115px">操作</th>
                        </tr>
                        </thead>
                        <tbody id="list"></tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
    var examTable;
    $(function () {
        examTable = $('#examTable').DataTable({
            "ajax": {
                url: "${ctx}/exam/examManage/examList",
                type: "post",
                cache: false,
                data: function (d) {
                    var categoryId = d.categoryId = $('#category ').val();
                    var checkStatusId = d.checkStatusId = $('#check-status-id option:selected ').val();
                    var cognitiveLevel = d.cognitiveLevel = $('#cognitive-level option:selected ').val();
                    var keywords = d.keywords = $('input[name="keywords"]').val();
                }
            },
            "bLengthChange": true,
            "aLengthMenu": [9, 20, 50],
            "sDom": '<"top">rt<"bottom"flpi><"clear">',
            "serverSide": true,//打开后台分页
            "bSort": false,
            "aaSorting": [[1, "DESC"]], //默认第几个排序
            "bStateSave": true, //状态保存
            "bFilter": false,
            "bAutoWidth": true,
            "iDisplayLength": 9,
            "aoColumnDefs": [
                //{"bVisible": false, "aTargets": [ 3 ]} //控制列的隐藏显示
                {
                    "orderable": false,
                    "aTargets": [0]
                } // 不参与排序的列
            ],
            "bScrollCollapse": true, //高度自适应
            "columns": [{
                "render": function (data, type, row, meta) {
                    var id = row.id;
                    return "<label class='i-checks'><input type='checkbox' name='checkbody' value='" + id + "'></label>";
                }
            },
                {
                    "data": "stem",
                    "render": function (data, type, row, meta) {
                        var id = row.id;
                        return "<u style='cursor:pointer' class='text-primary' onClick='exam_detail(\"试题详情\",\"${ctx}/exam/examManage/detail/exam/" + id + "\")' title='查看试题详情'><div class='stem'>" + data + "</div></u>";

                    }
                }, {
                    "render": function (data, type, row, meta) {
                        var categoryId = row.categoryId;
                        var categoryName = getCategoryName(categoryId);
                        return "<span >" + categoryName + "</span>";
                    },
                }, {
                    "data": "totalScore",
                }, {
                    "data": "outlineCode",
                }, {
                    "data": "cognitiveLevel",
                }, {
                    "data": "updateTime",
                }, {
                    "render": function (data, type, row, meta) {
                        var checkStatusId = row.checkStatusId;

                        if (checkStatusId == 0 || checkStatusId == 1 || checkStatusId == 3) {
                            return "<span class='label label-danger radius'>" + getCheckStatusNameById(checkStatusId) + "</span>";
                        }
                        return "<span class='label label-success radius'>" + getCheckStatusNameById(checkStatusId) + "</span>";
                    },
                }, {
                    "render": function (data, type, row, meta) {
                        var id = row.id;
                        var categoryId = row.categoryId;
                        /**
                         *@Author: 陈玉林
                         *@Date: 2017/8/24 10:25
                         *@Description: 未审核-0：审核、修改、删除
                         * 一审未过-1：审核、撤销审核、修改
                         * 一审通过-2：审核、撤销审核、修改
                         * 二审未过-3：审核、撤销审核、修改
                         * 二审通过-4：撤销审核、修改
                         */
                        return "<span style='cursor: pointer;'  class='text-c' onClick='exam_check(this,\"" + id + "\") '>审核</span>&nbsp;<a style='text-decoration:none' class='ml-5' onClick='exam_check_cancel(this,\"" + id + "\",\"" + categoryId + "\")' href='javascript:;'  title='撤销审核'><i class='fa fa-mail-reply'></i></a>&nbsp;<a style='text-decoration:none' class='ml-5' onClick='exam_update(\"" + id + "\",\"${ctx}/exam/examManage/update/page/\")'  href='javascript:;'  title='修改'><i class='glyphicon glyphicon-pencil'></i></a>&nbsp;<a style='text-decoration:none' class='ml-5'onClick='exam_del(this,\"" + id + "\")'  href='javascript:;'title='删除'><i class='glyphicon glyphicon-trash'></i> </a>&nbsp;<a style='text-decoration:none' class='ml-5'onClick='setExamObjective(\"" + id + "\",\"" + categoryId + "\")'  href='javascript:;'title='设定客观化'><i class='fa fa-gear'></i> </a>";
                    }
                }],
        });
    });
    /*********************************************************************************选择框**********************************************************/
    $(document).ajaxComplete(function () {
        $('input[type=checkbox]').iCheck({
            checkboxClass: "icheckbox_square-green",
            radioClass: "iradio_square-green"
        });

        $("#all_checked").on('ifChecked', function (event) {
            $("input[name='checkbody']").iCheck('check');
        });
        $("#all_checked").on('ifUnchecked', function (event) {
            $("input[name='checkbody']").iCheck('uncheck');
        });

    })

    //获取被选中checkbox值
    function getCheckedVal() {
        var checkData = new Array();
        var checks = $("input[name='checkbody']:checked");
        if (checks.length == 0) {
            layer.alert('未选中任何项！', {
                closeBtn: 0
            });
            return;

        }
        checks.each(function () {
            checkData.push($(this).val());
        });
        return checkData;
    };

    /*********************************************************************************选择框**********************************************************/
    /**
     *@author: 陈玉林
     *@date: 2017/12/13 9:33
     *@description: 试题导出
     */
    function exportExam() {
        var flag = true;
        //验证权限
        $.ajax({
            url: "${ctx}/exam/examManage/volidateAuth/dcst",
            type: "get",
            dataType: "json",
            async: false,
            success: function (data) {
                if (data.code != 0) {
                    layer.alert(data.msg, {
                        closeBtn: 0
                    });
                    flag = false;
                }
            }
        });
        if (flag == false) {
            return;
        }


        var checkData = getCheckedVal();
        if (checkData == undefined) {
            return;
        }
        /*判断试题分类是否一样*/
        if (checkData.length > 1) {
            for (var i = 0; i < checkData.length; i++) {
                var categoryId = checkData[0].substring(0, 2);
                if (categoryId != checkData[i].substring(0, 2)) {
                    layer.alert('请选择同种类型的试题再进行导出!', {
                        closeBtn: 0
                    })
                    return;
                }
            }
        }
        window.location.href = '${ctx}/exam/examManage/export?checkedId=' + checkData;
    }

    //获取试题审核状态名称
    function getCheckStatusNameById(id) {
        var checkStatusId = "";
        switch (id) {
            case 0:
                checkStatusId = "未审核";
                break;
            case 1:
                checkStatusId = "一审未过";
                break;
            case 2:
                checkStatusId = "一审通过";
                break;
            case 3:
                checkStatusId = "二审未过";
                break;
            case 4:
                checkStatusId = "二审通过";
                break;
            default:
                break;
        }
        return checkStatusId;
    }

    //试题搜索
    $("#search-exam").click(function () {
        examTable.ajax.reload();
    });

    /* 查看试题详情 */
    function exam_detail(title, url, id, w, h) {
        layer.open({
            title: title,
            type: 2,
            area: ['100%', '100%'],
            shadeClose: true,
            content: url
        });
    }


    /**
     *@Author: 陈玉林
     *@Date: 2017/8/11 15:02
     *@Description: 试题修改
     */
    function exam_update(id, url) {
        var flag = true;
        $.ajax({
            url: "${ctx}/exam/examManage/update/volidateAuth/" + id,
            type: "get",
            async: false,
            dataType: "json",
            success: function (data) {
                if (data.code != 0) {
                    layer.alert(data.msg, {
                        closeBtn: 0
                    });
                    flag = false;
                }
            }
        });
        if (flag == false) {
            return;
        }

        layer.open({
            type: 2,
            title: '试题修改',
            area: ['100%', '100%'],
            shadeClose: true,
            content: url + id, //iframe的url，yes是否有滚动条
        });

    }

    /*获取试题分类*/
    function getCategory() {
        var id = $("#examClass").val();
        var text = "";
        if (id == -1) {
            $("#category").empty();
            text = "<option value='-1'>全部</option>";
            $("#category").html(text);
            return;
        }
        $.ajax({
            url: '${ctx}/paper/exam/category',
            data: {"id": id},
            dataType: "JSON",
            type: "GET",
            success: function (data) {
                $(data).each(function (index, obj) {
                    text += "<option value='" + obj.id + "'>" + obj.name + "</option>";
                })
                $("#category").html(text);
            }

        })
    }

    /*设置为客观化*/
    function setExamObjective(id, categoryId) {
        debugger
        layer.confirm('是否通过设置为客观化？', {icon: 3, btn: ['设定为客观化', '取消设置客观化']}, function (index) {                 //这里的icon:3 是‘？’图标，在上次博客试出来的共存方法
            if (categoryId == '16') {
                layer.alert('该试题已经是客观化试题，无需进行该操作！', {
                    closeBtn: 0
                });
                return;
            }
            if (categoryId != '8') {
                layer.alert('该试题非成人穴位试题，不能进行该操作！', {
                    closeBtn: 0
                });
                return;
            }
            layer.close(index);
            $.ajax({
                type: 'GET',
                url: "${ctx}/exam/examManage/setToObjective",
                data: {id: id},
                dataType: 'json',
                success: function (data) {
                    if (data.code == 0) {
                        layer.msg(data.msg, {
                            icon: 1,
                            time: 2000
                        });
                        examTable.ajax.reload();
                    } else {
                        layer.alert(data.msg, {
                            closeBtn: 0
                        });
                    }
                },
                error: function (data) {
                    console.log(data.msg);
                },
            });
        })
        $('.layui-layer-btn1').click(function () {
            if (categoryId != '16') {
                layer.alert('该试题非客观化试题，不能进行该操作！', {
                    closeBtn: 0
                });
                return;
            }
            $.ajax({
                url: "${ctx}/exam/examManage/cancelObjective",
                type: "get",
                dataType: "json",
                data: {id: id},
                success: function (data) {
                    if (data.code == 0) {
                        layer.msg(data.msg, {
                            icon: 1,
                            time: 2000
                        });
                        examTable.ajax.reload();
                    } else {
                        layer.alert(data.msg, {
                            closeBtn: 0
                        });
                    }
                }
            });
        })
    }

    /**
     *@Author: 陈玉林
     *@Date: 2017/8/11 15:02
     *@Description: 试题审核
     * 完成审核后不能再进行审核
     */
    function exam_check(obj, id) {
        var realCheckStatusId = 0;
        //先获取试题审核状态
        $.ajax({
            url: "${ctx}/exam/examManage/check/getCheckStatusId",
            type: "get",
            dataType: "json",
            data: {id: id},
            async: false,
            success: function (data) {
                realCheckStatusId = data.data.checkStatusId;
            }
        });
        if (realCheckStatusId == 4) {
            layer.alert('该试题已经审核完毕！', {
                closeBtn: 0
            });
            return;
        }

        layer.confirm('是否通过审核？', {icon: 3, btn: ['通过', '不通过']}, function (index) {                 //这里的icon:3 是‘？’图标，在上次博客试出来的共存方法
            layer.close(index);
            /*
                审核通过，审核状态要不是2，要不是4
                0,1通过后状态变为2，
                2,3通过后变为4
              */
            var checkStatusId = realCheckStatusId;
            if (checkStatusId == 0 || checkStatusId == 1) {
                checkStatusId = 2;
            } else if (checkStatusId == 2 || checkStatusId == 3) {
                checkStatusId = 4;
            }
            var checkRemark = '';
            $.ajax({
                type: 'GET',
                url: "${ctx}/exam/examManage/check",
                data: {id: id, checkStatusId: checkStatusId, checkRemark: checkRemark},
                dataType: 'json',
                success: function (data) {
                    debugger
                    if (data.code == 0) {
                        layer.msg(data.msg, {
                            icon: 1,
                            time: 2000
                        });
                        $(obj).parent().parent().find(".label").addClass("label-success");
                        $(obj).parent().parent().find(".label").removeClass("label-danger");
                        $(obj).parent().parent().find(".label").html(getCheckStatusNameById(checkStatusId));
                    } else {
                        layer.alert(data.msg, {
                            closeBtn: 0
                        });
                    }
                },
                error: function (data) {
                    console.log(data.msg);
                },
            });
        })
        $('.layui-layer-btn1').click(function () {                           //  .layui-layer-btn1 = 右边按钮class名
            layer.prompt({title: '请输入备注信息', formType: 2}, function (checkRemark, index) {
                layer.close(index);
                /*
                    审核不通过，要不是1就是3
                    0，1不通过为1
                    2，3不通过为3
                */
                var checkStatusId = realCheckStatusId;
                if (checkStatusId == 0 || checkStatusId == 1) {
                    checkStatusId = 1;
                } else if (checkStatusId == 2 || checkStatusId == 3) {
                    checkStatusId = 3;
                }
                $.ajax({
                    url: "${ctx}/exam/examManage/check",
                    type: "get",
                    dataType: "json",
                    data: {id: id, checkStatusId: checkStatusId, checkRemark: checkRemark},
                    success: function (data) {
                        if (data.code == 0) {
                            layer.msg(data.msg, {
                                icon: 1,
                                time: 2000
                            });
                            $(obj).parent().parent().find(".label").removeClass("label-success");
                            $(obj).parent().parent().find(".label").addClass("label-danger");
                            $(obj).parent().parent().find(".label").html(getCheckStatusNameById(checkStatusId));
                        } else {
                            layer.alert(data.msg, {
                                closeBtn: 0
                            });
                        }
                    }
                });
            });
        })
    }

    /**
     *@Author: 陈玉林
     *@Date: 2017/8/24 9:16
     *@Description: 撤销审核
     * 未审核试题不能撤销审核
     * 若是客观化穴位定位，则不让撤销，必须撤销需要先取消客观化
     */
    function exam_check_cancel(obj, id, categoryId) {
        if (categoryId == 16) {
            layer.alert('该试题为客观化试题,如需撤销审核请先取消客观化设定！', {
                closeBtn: 0
            });
            return;
        }
        var realCheckStatusId = 0;
        //先获取试题审核状态
        $.ajax({
            url: "${ctx}/exam/examManage/check/getCheckStatusId",
            type: "get",
            dataType: "json",
            async: false,
            data: {id: id},
            success: function (data) {
                realCheckStatusId = data.data.checkStatusId;
            }
        });
        if (realCheckStatusId == 0) {
            layer.alert('该试题还未经审核！', {
                closeBtn: 0
            });
            return;
        }
        layer.confirm('确认要撤销审核吗？', function (index) {
            var checkStatusId = realCheckStatusId;
            if (checkStatusId == 1 || checkStatusId == 2) {
                checkStatusId = 0;
            } else if (checkStatusId == 3 || checkStatusId == 4) {
                checkStatusId = 2;
            }
            $.ajax({
                data: {id: id, checkStatusId: checkStatusId},
                type: 'GET',
                url: '${ctx}/exam/examManage/check/cancel',
                dataType: 'json',
                success: function (data) {
                    if (data.code == 0) {
                        layer.msg(data.msg, {
                            icon: 1,
                            time: 2000
                        });
                        if (checkStatusId == 0) {
                            $(obj).parent().parent().find(".label").addClass("label-danger");
                            $(obj).parent().parent().find(".label").removeClass("label-success");
                            $(obj).parent().parent().find(".label").html(getCheckStatusNameById(checkStatusId));
                        } else {
                            $(obj).parent().parent().find(".label").addClass("label-success");
                            $(obj).parent().parent().find(".label").removeClass("label-danger");
                            $(obj).parent().parent().find(".label").html(getCheckStatusNameById(checkStatusId));
                        }
                    } else {
                        layer.alert(data.msg, {
                            closeBtn: 0
                        });
                    }
                },
                error: function (data) {
                    console.log(data.msg);
                },
            });
        });
    }


    /*试题-删除*/
    function exam_del(obj, id) {
        var realCheckStatusId = 0;
        //先获取试题审核状态
        $.ajax({
            url: "${ctx}/exam/examManage/check/getCheckStatusId",
            type: "get",
            dataType: "json",
            async: false,
            data: {id: id},
            success: function (data) {
                realCheckStatusId = data.data.checkStatusId;
            }
        });
        if (realCheckStatusId != 0) {
            layer.alert('该试题已经开始审核，请撤销审核至“未审核”状态后再进行删除！', {
                closeBtn: 0
            });
            return;
        }
        layer.confirm('确认要删除吗？', function (index) {
            $.ajax({
                data: {id: id},
                type: 'GET',
                url: '${ctx}/exam/examManage/delete',
                dataType: 'json',
                success: function (data) {
                    if (data.code == 0) {
                        layer.msg(data.msg, {
                            icon: 1,
                            time: 2000
                        });
                        examTable.ajax.reload();
                    } else {
                        layer.alert(data.msg, {
                            closeBtn: 0
                        });
                    }
                },
                error: function (data) {
                    console.log(data.msg);
                },
            });
        });
    }


    function getCategoryName(category) {
        switch (category) {
            case 1:
                category = "问答题-腧穴";
                break;
            case 2:
                category = "问答题-内科";
                break;
            case 3:
                category = "问答题-伤科";
                break;
            case 4:
                category = "问答题-妇科";
                break;
            case 5:
                category = "问答题-儿科";
                break;
            case 6:
                category = "问答题-触诊";
                break;
            case 7:
                category = "穴位定位-儿科穴位";
                break;
            case 8:
                category = "穴位定位-成人穴位";
                break;
            case 9:
                category = "单项手法-儿科手法";
                break;
            case 10:
                category = "单项手法-成人手法";
                break;
            case 11:
                category = "单项手法-触诊诊断";
                break;
            case 12:
                category = "成套手法-内科";
                break;
            case 13:
                category = "成套手法-伤科";
                break;
            case 14:
                category = "成套手法-妇科";
                break;
            case 15:
                category = "成套手法-儿科";
                break;
            case 16:
                category = "穴位定位-客观化";
                break;
            default:
                break;
        }
        return category;
    };
</script>

</body>


</html>
